<?php
	$monthNames = array(
		1 => 'Január', 2 => 'Február', 3 => 'Marec', 4 => 'Apríl', 5 => 'Máj', 6 => 'Jún',
		7 => 'Júl', 8 => 'August', 9 => 'September', 10 => 'Október', 11 => 'November', 12 => 'December'
	);
?>
<?php
$this->pageTitle = 'Depozity';
?>

<div class="listing">
	<h3>Depozity</h3>
	<div class="top_links">
		<?php
			$totalTitle = 'SPOLU';
			if ($actualType == 'total') {
				echo '<strong>' . $totalTitle . '</strong>';
			} else {
				echo $this->Html->link($totalTitle, array('controller' => 'commission', 'action' => 'stats'));
			}
		?>
		<span> | </span>
		<?php
			$companyTitle = 'Firma';
			if ($actualType == 'company') {
				echo '<strong>' . $companyTitle . '</strong>';
			} else {
				echo $this->Html->link($companyTitle, array('controller' => 'commission', 'action' => 'stats', 'company'));
			}
		?>
		<span> | </span>
		<?php
			$netTitle = 'Siete';
			if ($actualType == 'net') {
				echo '<strong>' . $netTitle . '</strong>';
			} else {
				echo $this->Html->link($netTitle, array('controller' => 'commission', 'action' => 'stats', 'net'));
			}
		?>
		<span> | </span>
		<?php
			$brokerTitle = 'Makléri';
			if ($actualType == 'broker') {
				echo '<strong>' . $brokerTitle . '</strong>';
			} else {
				echo $this->Html->link($brokerTitle, array('controller' => 'commission', 'action' => 'stats', 'broker'));
			}
		?>
		<span> | </span>
		<?php
			$companiesTitle = 'Finančné spoločnosti';
			if ($actualType == 'companies') {
				echo '<strong>' . $companiesTitle . '</strong>';
			} else {
				echo $this->Html->link($companiesTitle, array('controller' => 'commission', 'action' => 'stats', 'companies'));
			}
		?>
	</div>
	<table class="list">
		<tbody>
			<tr>
				<td>&nbsp;</td>
				<?php foreach ($monthNames as $index => $month): ?>
				<td>
					<?php
						$shortMonthName = mb_substr($month, 0, 3);
						if ($index == $actualMonth) {
							echo '<strong>' . $shortMonthName . '</strong>';
						} elseif ($actualYear) {
							echo $this->Html->link($shortMonthName, array('controller' => 'commission', 'action' => 'stats', $actualType, $actualYear, $index));
						} else {
							echo $shortMonthName;
						}
					?>
				</td>
				<?php endforeach; ?>
			</tr>

			<?php
			foreach ($years as $year):
			?>
			<tr>
				<td>
					<?php
						if ($year == $actualYear) {
							echo '<strong>' . $year . '</strong>';
						} else {
							echo $this->Html->link($year, array('controller' => 'commission', 'action' => 'stats', $actualType, $year));
						}
					?>
				</td>
				<?php if ($year == max($years)): ?>
				<td class="total_commission" rowspan="<?php echo count($years); ?>" colspan="12" style="font-size: <?php echo 12 * 2 * count($years); ?>px;">
					<?php
						// musime tu replacnut &amp; lebo Html->link escapuje taketo znaky a preto by sa nam nevypisalo dobre euro, snad sa neposere nieco ine ;)
						echo str_replace('&amp;', '&', $this->Html->link(number_format($totalCommission, 2, ',', ' ') . ' &euro;', array('controller' => 'commission', 'action' => 'index', $actualType, $actualYear, $actualMonth)));
					?>
				</td>
				<?php endif; ?>
			</tr>
			<?php endforeach; ?>
		</tbody>
	</table>
</div>